<%
'错误信息
Set dError=Server.CreateObject("Scripting.Dictionary")
dError.add "1","未找到数据"
dError.add "2","没有权限"
dError.add "3","没有登录"


'是否
Set dBool=Server.CreateObject("Scripting.Dictionary")
dBool.add "True","是"
dBool.add "False","否"

' 权限字典
Set dAuthority=Server.CreateObject("Scripting.Dictionary")
dAuthority.add "1","查询"
dAuthority.add "2","查询、查看"
dAuthority.add "3","查询、查看、添加"
dAuthority.add "4","查询、查看、添加、编辑"
dAuthority.add "5","查询、查看、添加、编辑、删除"
dAuthority.add "15","管理员"


'代替ASP中的Request函数，可以对一切的SQL注入Say NO
Function SafeRequest(ParaName,ParaType)
'--- 传入参数 ---
'ParaName:参数名称-字符型
'ParaType:参数类型-数字型(1表示以上参数是数字，0表示以上参数为字符)
	Dim ParaValue
	ParaValue=Request(ParaName)
	If ParaType=1 then
		If Not IsNumeric(ParaValue) then
			Response.Write "参数" & ParaName & "必须为数字型！"
			Response.End
		End If
	Else
		ParaValue=Replace(ParaValue,"'","''")
	End If
	SafeRequest=ParaValue
End Function

function ULen(byval str)
	Dim RegExpObj,ReGCheck
	Set RegExpObj=new RegExp
	RegExpObj.Pattern="^[\u4e00-\u9fa5|\uFF00-\uFFFF]+$"
	Dim l,t,c,i
	l=Len(str)
	t=l
	For i=1 to l
		c=Mid(str,i,1)
		ReGCheck=RegExpObj.test(c)
		If ReGCheck Then
			t=t+1
		End If
	Next
	Set RegExpObj=nothing
	ULen=t
end function

function FillSpace(str,len)
	dim i,u
	u=ULen(str)
	if u<len then
		for i=1 to len-u
			str=str&"&nbsp;"
		next
	end if
	FillSpace=str
end function

'执行command对象函数，sql_text为要执行的sql语句，return_id为是否要返回insert后的自动编号
function ExecuteCommand(sql_text,return_id)
	dim last_id,cmd,rs_last
	set cmd=Server.CreateObject("ADODB.Command")
	cmd.ActiveConnection = conn
	cmd.CommandText = sql_text
	' response.write(sql_text)
	'response.end
	cmd.Execute
	if lcase(left(ltrim(sql_text),6))="insert" and return_id then
		cmd.CommandText = "select last_insert_rowid()"
		set rs_last=cmd.Execute
		last_id=rs_last.getstring
    ' response.write(last_id)
		rs_last.close
		set rs_last=nothing
	end if
	set cmd=nothing
	ExecuteCommand=last_id
end function
function ExecuteCommand_ndflow(sql_text,return_id,conn_ndflow)
	dim last_id,cmd,rs_last
	set cmd=Server.CreateObject("ADODB.Command")
	cmd.ActiveConnection = conn_ndflow
	cmd.CommandText = sql_text
	' response.write(sql_text)
	' response.end
	cmd.Execute
	if lcase(left(ltrim(sql_text),6))="insert" and return_id then
		cmd.CommandText = "select last_insert_rowid()"
		set rs_last=cmd.Execute
		last_id=rs_last.getstring
    ' response.write(last_id)
		rs_last.close
		set rs_last=nothing
	end if
	set cmd=nothing
	ExecuteCommand_ndflow=last_id
end function




'检查登录用户是否在这个岗位
function CheckPost(aaTemp,iPost)
	dim i
	CheckPost=false
	if iPost="" then exit function
	if not IsArray(aaTemp) then exit function
	for i=0 to ubound(aaTemp,2)
		if aaTemp(0,i)=cint(iPost) then
			CheckPost=true
			exit function
		end if
	next
end function

'检查登录用户是否有权限，只要有任何一个岗位低于iFlag，就返回false
function CheckFlag(aaTemp,iFlag)
	dim i
	CheckFlag=false
	if not CheckLogin() then
		call JumpErrorPage(3)
		exit function
	end if
	if iFlag="" then exit function
	if not IsArray(aaTemp) then exit function
	for i=0 to ubound(aaTemp,2)
		if aaTemp(1,i)<cint(iFlag) then exit function
	next
	CheckFlag=true
end function

'检查登录用户是否有某个岗位的某个权限
function CheckPostFlag(aaTemp,iPost,iFlag)
	CheckPostFlag=false
	if not CheckLogin() then
		call JumpErrorPage(3)
		exit function
	end if
	if iPost="" or iFlag="" then exit function
	if not IsArray(aaTemp) then exit function
	if GetFlagValue(aaTemp,iPost)>=cint(iFlag) then
		CheckPostFlag=true
	end if
end function

'获取某个岗位的权限
function GetFlagValue(aaTemp,iPost)
	dim i
	GetFlagValue=0
	if iPost="" then exit function
	if not IsArray(aaTemp) then exit function
	for i=0 to ubound(aaTemp,2)
		if aaTemp(0,i)=cint(iPost) then
			GetFlagValue=cint(aaTemp(1,i))
			exit function
		end if
	next
end function

'获得权限的中文字符
' function GetFlagString(iFlag)
	' select case iFlag
		' case 1 GetFlagString="查询"
		' case 2 GetFlagString="查询、查看"
		' case 3 GetFlagString="查询、查看、添加"
		' case 4 GetFlagString="查询、查看、添加、编辑"
		' case 5 GetFlagString="查询、查看、添加、编辑、删除"
		' case 15 GetFlagString="管理员"
		' case else GetFlagString=""
	' end select
' end function

'获得岗位的中文字符
' function GetPostString(iPost)
	' select case iPost
		' case 0 GetPostString="用户权限"
		' case 1 GetPostString="输入"
		' case 2 GetPostString="作业"
		' case 3 GetPostString="审核"
		' case 4 GetPostString="财务"
		' case 5 GetPostString="核销单管理"
		' case else GetPostString=""
	' end select
' end function



'获得岗位的中文字符
function GetPostString(aaTemp,iPost)
	dim i
	GetPostString=""
	if not IsArray(aaTemp) then exit function
	for i=0 to ubound(aaTemp,2)
		if aaTemp(0,i)=cint(iPost) then
			GetPostString=aaTemp(1,i)
			exit function
		end if
	next
end function


'判断是否是：不等于空字符串并且不等于0的数字
function IsNumberNz(s)
	IsNumberNz=false
	if IsNumeric(s) then
		if s<>"" and s<>0 then
			IsNumberNz=true
		end if
	end if
end function


'跳转到错误页面，id是错误编号，url是跳转前的页面地址
function JumpErrorPage(iError)
	dim oldurl
	oldurl="http://"&request.ServerVariables("HTTP_HOST")&request.ServerVariables("Url")
	if request.ServerVariables("QUERY_STRING")<>"" then oldurl=oldurl&"?"&request.ServerVariables("QUERY_STRING")
	response.redirect("error.asp?id="&iError&"&url="&Server.URLEncode(oldurl))
end function

function ShowError(iError)
	response.write("错误："&dError(cstr(iError)))
	response.end
end function

function CheckLogin()
	CheckLogin=false
	if session("sSystem")="Laketune" and session("bLogin")=true then CheckLogin=true
end function



' 判断用户访问的httphost地址，因为如果判断用户ip，可能是用vpn拨号进来的，那就可能是10.8.2这段，会误判
function CheckLan()
	CheckLan=false
	' response.write(request.ServerVariables("HTTP_HOST") )
	if request.ServerVariables("HTTP_HOST")="192.168.20.35" or request.ServerVariables("HTTP_HOST")="127.0.0.1" or left(request.ServerVariables("HTTP_HOST"),9)="localhost" then CheckLan=true
end function


function CheckPassword(sPassword)
	CheckPassword=false
	Dim RegExpObj
	Set RegExpObj=new RegExp
	RegExpObj.Pattern="^(?![^a-zA-Z]+$)(?!\D+$).{6,10}$"
	CheckPassword=RegExpObj.test(sPassword)
	Set RegExpObj=nothing
end function


'==================================================================  
'函数：FormatTime   
'功能：日期时间格式化   
'参数：DateTime,日期时间   
'Template,格式化模板   
'返回：格式化后的字串   
'备注：模板标签注释   
'　　　{Y}:年   
'　　　{y}:2位年   
'　　　{M}:月   
'　　　{m}:补位月，例：01,02   
'　　　{ME}:英文月份   
'　　　{Me}:英文月份缩写   
'　　　{D}:日   
'　　　{d}:补位日   
'　　　{H}:时   
'　　　{h}:补位时   
'　　　{N}:分   
'　　　{n}:补位分   
'　　　{S}:秒   
'　　　{s}:补位秒   
'　　　{W}:星期几英文   
'　　　{w}:星期几英文缩写     
'==================================================================  
  
Function FormatTime(DateTime,Template)   
    If (Not IsDate(DateTime)) or Template = "" Then  
        FormatTime = Template   
        Exit Function  
    End If  
    Dim dtmY,dtmM,dtmD,dtmH ,dtmN,dtmS,dtmW   
    Dim arrFW,arrSW,arrFM,arrSM   
    dtmY = Year(DateTime)   
    dtmM = Month(DateTime)   
    dtmD = Day(DateTime)   
    dtmH = Hour(DateTime)   
    dtmN = Minute(DateTime)   
    dtmS = Second(DateTime)   
    dtmW = WeekDay(DateTime)   
    arrFW = Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")   
    arrSW = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")   
    arrFM = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")   
    arrSM = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")     
    Template = Replace(Template,"{Y}",dtmY)   
    Template = Replace(Template,"{y}",Right(dtmY,2))   
    Template = Replace(Template,"{M}",dtmM)   
    Template = Replace(Template,"{m}",Right("00"&dtmM,2))   
    Template = Replace(Template,"{ME}",arrFM(dtmM-1))   
    Template = Replace(Template,"{Me}",arrSM(dtmM-1))   
    Template = Replace(Template,"{D}",dtmD)   
    Template = Replace(Template,"{d}",Right("00"&dtmD,2))   
    Template = Replace(Template,"{H}",dtmH )   
    Template = Replace(Template,"{h}",Right("00"&dtmH ,2))   
    Template = Replace(Template,"{N}",dtmN)   
    Template = Replace(Template,"{n}",Right("00"&dtmN,2))   
    Template = Replace(Template,"{S}",dtmS)   
    Template = Replace(Template,"{s}",Right("00"&dtmS,2))   
    Template = Replace(Template,"{W}",arrFW(dtmW-1))   
    Template = Replace(Template,"{w}",arrSW(dtmW-1))   
    FormatTime = Template   
End Function



%>
